package com.property.manage.controller.dict;

import com.guardchina.framework.mybatis.model.CustomPage;
import com.property.manage.model.dict.DictEntity;
import com.property.manage.model.equipment.EquipmentVo;
import com.property.manage.service.dict.DictService;
import com.property.manage.service.equipment.EquipmentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * 描述
 *
 * @author lwb
 * @since 2020/7/15
 */
@Api(tags = "字典管理")
@RestController
@RequestMapping("/dict")
@AllArgsConstructor
@Validated
public class DictController {
    @Autowired
    private DictService dictService;


    @ApiOperation("根据code查询类型下拉框")
    @GetMapping("/page")
    public List<DictEntity> getCode(@ApiParam("字典code") @RequestParam(value = "code") String code){
        return dictService.findByCode(code);
    }



    @ApiOperation("添加")
    @PostMapping("/add")
    public void add(
                    @ApiParam("名称")@RequestParam(value = "name")@NotBlank(message = "名字不能为空") String name,
                    @ApiParam("名称标志（必须唯一）")@RequestParam(value = "code",required = false)@NotBlank(message = "唯一标志不能为空") String code,
                    @ApiParam("值")@RequestParam(value = "value")@NotNull(message = "值不能为空") Integer value,
                    @ApiParam("上级id")@RequestParam(value = "superiorId")@NotNull(message = "上级id不能为空") Integer superiorId


    ){
        dictService.add(name,code,value,superiorId);
    }


    @ApiOperation("删除")
    @PostMapping("/delete")
    public void delete(@ApiParam("id") @RequestParam("id") @NotNull(message = "id为空") Integer id){
        dictService.delete(id);
    }


}
